package com.lightdz.tshirtdz.controller;

import com.lightdz.tshirtdz.bll.BrowserHistoryeBll;
import com.lightdz.tshirtdz.model.api.ApiProduct;
import com.lightdz.tshirtdz.model.api.ApiResponse;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @ Description：我的浏览记录
 * @ Author     ：zbl
 * @ Date       ：Created in 16:39 09/08/2018
 * @ Modified By：
 */

@RequestMapping(value = "/browser")
@RestController
public class BrowserHistoryController {

    @Autowired
    BrowserHistoryeBll browserBll;

    /**
     * 删除我的浏览记录
     *
     */
    @GetMapping(value = "/deletebrowser")
    public ApiResponse<Boolean> deleteBrowser(String wxId, long pid) {
        return browserBll.deleteBrowser(wxId, pid);
    }

    /**
     * 获取我的浏览记录
     *
     * @param wxId
     * @return
     */
    @GetMapping(value = "/getbrolist")
    public ApiResponse<List<ApiProduct>> getBroList(String wxId) {



        return browserBll.getBrowseList(wxId);
//        try {
//            //
//            SqlSession sqlSession = getSqlSession();
//            //得到UserMapperI接口的实现类对象，UserMapperI接口的实现类对象由sqlSession.getMapper(UserMapperI.class)动态构建出来
//            IBrowser mapper = sqlSession.getMapper(IBrowser.class);
//
//            //执行查询操作，将查询结果自动封装成User返回
//            //List<BrowseHistoryEntity> name = mapper.getBroList();
//            int name = mapper.getOne(2);
//            //使用SqlSession执行完SQL之后需要关闭SqlSession
//            sqlSession.close();
//            System.out.println(name);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }


}
